library(readr)
library(Hmisc)
MPOs <- read_csv("MPO_database_shortform.csv",
                 col_types = cols(ACT_COMM = col_logical(), 
                                  ACT_MODEL = col_integer(),
                                  AIR_COMM = col_logical(), 
                                  AIR_SEAT = col_integer(),
                                  AIR_VOTE = col_integer(), 
                                  BIK_COMM = col_logical(),
                                  BRD_SZ = col_integer(), 
                                  DES_YR = col_integer(),
                                  FRT_MODEL = col_integer(), 
                                  INDEPENDENT = col_logical(),
                                  MPO_ID = col_integer(),
                                  MULTISTATE = col_logical(), 
                                  PED_COMM = col_logical(),
                                  POP10 = col_integer(), 
                                  STATE3 = col_character(),
                                  TDM_INT = col_logical(), 
                                  TDM_TYPE = col_integer(),
                                  TRN_COMM = col_logical(), 
                                  TRN_DIRECT = col_logical(),
                                  TRN_MODEL = col_integer(), 
                                  TRN_REP = col_logical(),
                                  TRN_SEAT = col_integer(), 
                                  TRN_VOTE = col_integer(),
                                  WEIGHTED = col_logical()))

MPOs$TDM_TYPE <- factor(MPOs$TDM_TYPE,
                        levels = c(-1, 0, 1, 2, 3),
                        labels = c('unknown',
                                   'simpleGrowth',
                                   '4-step',
                                   'devABM',
                                   'ABM'))
MPOs$ACT_MODEL <- factor(MPOs$ACT_MODEL,
                         levels = c(-1, 0, 1, 2),
                         labels = c('unknown',
                                    'combined',
                                    'separate',
                                    'unmodeled'))
MPOs$TRN_MODEL <- factor(MPOs$TRN_MODEL,
                         levels = c(-1, 0, 1, 2),
                         labels = c('unknown',
                                    'assigned',
                                    'modeChoice',
                                    'unmodeled'))
MPOs$FRT_MODEL <- factor(MPOs$FRT_MODEL,
                         levels = c(-1,0,1),
                         labels = c('unknown',
                                    'assigned',
                                    'unmodeled'))

var.labels = c(MPO_ID = "ID number",
               MULTISTATE = "Multistate",
               STATE1 = "MPO's state",
               STATE2 = "2nd state if applicable",
               STATE3 = "3rd state if applicable",
               DES_YR = "Year the MPO was designated",
               POP10 = "Population from the 2010 Census",
               INDEPENDENT = "Not a part of a CoG or City",
               BRD_SZ = "Seats on the Policy Board",
               BRD_VOTE = "Voting seats on the Policy Board",
               WEIGHTED = "Weighted voting",
               TRN_SEAT = "Transit seats on the Policy Board",
               TRN_VOTE = "Voting transit seats on the Policy Board",
               TRN_REP = "Transit representation",
               TRN_DIRECT = "Direct transit representation",
               AIR_SEAT = "Airport seats on the Policy Board",
               AIR_VOTE = "Voting airport seats on the Policy Board",
               TRN_REP_PRCT = "% transit representation by vote",
               AIR_REP_PRCT = "% air representation by vote",
               AIR_COMM = "Airport committee",
               ACT_COMM = "Active transport committee",
               BIK_COMM = "Dedicated bicycling committee",
               PED_COMM = "Dedicated pedestrian committee",
               TRN_COMM = "Transit committee",
               TDM_INT = "Internal travel demand model",
               TDM_TYPE = "Travel demand model type",
               ACT_MODEL = "Active transport modeling",
               TRN_MODEL = "Transit modeling",
               FRT_MODEL = "Freight modeling"
               )
label(MPOs) = as.list(var.labels[match(names(MPOs), names(var.labels))])
